package com.yanqu.road.server.cmd.activity.oldplayerreturn;

import com.yanqu.road.pb.activity.OldPlayerReturnProto;
import com.yanqu.road.pb.player.PlayerProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/12/8 15:45
 */
@Cmd(code = GameProtocol.S_BIND_RETURN_ROLE_SUCCESS_RESP, desc = "绑定成功返回")
public class BindReturnRoleSuccessRespCmd extends AbstractCommand {
    private int result;
    private long bindServerId;
    private long bindUserId;
    private long vipExp;
    private PlayerProto.PlayerBaseTempMsg bindUserInfo;


    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.BindReturnRoleSuccessRespMsg msg = OldPlayerReturnProto.BindReturnRoleSuccessRespMsg.parseFrom(packet.getBytes());
        result = msg.getRet();
        bindServerId = msg.getBindServerId();
        bindUserId = msg.getBindUserId();
        vipExp = msg.getVipExp();
        bindUserInfo = msg.getBindUserInfo();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (result == 0) {
            ret = player.getModule(OldPlayerReturnModule.class).bindReturnRoleSuccessResp(bindServerId, bindUserId, bindUserInfo, vipExp);
        } else {
            ret = result;
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        OldPlayerReturnProto.BindReturnRoleRespMsg.Builder respMsg = OldPlayerReturnProto.BindReturnRoleRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.U_BIND_RETURN_ROLE, respMsg);
    }
}
